package com.jinzhi.jzweb.controller;


import java.util.*;

import cn.hutool.core.date.DateTime;
import com.jinzhi.jzapi.domain.UserDO;
import com.jinzhi.jzapi.service.UserService;
import com.jinzhi.jzweb.domain.JazSysLabelDO;
import com.jinzhi.jzweb.service.JazUserCommentClassifyService;
import com.jinzhi.jzweb.service.JazUserCommentDescriptionService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.common.annotation.Log;
import com.jinzhi.common.base.BaseController;
import com.jinzhi.jzweb.domain.JazUserCommentDO;
import com.jinzhi.jzweb.service.JazUserCommentService;
import com.jinzhi.common.utils.Result;

/**
 * 
 * <pre>
 * 评价管理
 * </pre>
 * <small> 2023-04-18 09:46:08 | Long</small>
 */
@Controller
@RequestMapping("/jzweb/jazUserComment")
public class JazUserCommentController extends BaseController {
	@Autowired
	private JazUserCommentService jazUserCommentService;
	@Autowired
	UserService userService;
	@Autowired
	private JazUserCommentDescriptionService jazUserCommentDescriptionService;
	@Autowired
	private JazUserCommentClassifyService jazUserCommentClassifyService;

	@GetMapping()
	@RequiresPermissions("jzweb:jazUserComment:jazUserComment")
	String JazUserComment(){
	    return "jzweb/jazUserComment/jazUserComment";
	}

	@GetMapping("/evaluationDescription")
	@RequiresPermissions("jzweb:jazUserCommentDescription:jazUserCommentDescription")
	String evaluationDescription(){
	    return "jzweb/evaluationDescription/index";
	}

	@GetMapping("/evaluationDescription/info/{id}/{type}")
	String evaluationDescriptionAdd(@PathVariable("id") String id,@PathVariable("type") String type,Model model){
		model.addAttribute("userId",id);
		model.addAttribute("infoType",type);
		model.addAttribute("myData",jazUserCommentDescriptionService.selectById(id));
	    return "jzweb/evaluationDescription/add";
	}

	@GetMapping("/evaluationClassification")
	@RequiresPermissions("jzweb:jazUserCommentClassify:jazUserCommentClassify")
	String evaluationClassification(){
		return "jzweb/evaluationClassification/index";
	}

	@GetMapping("/evaluationClassification/info/{id}/{type}")
	String eevaluationClassificationAdd(@PathVariable("id") String id,@PathVariable("type") String type,Model model){
		model.addAttribute("userId",id);
		model.addAttribute("infoType",type);
		model.addAttribute("myData", jazUserCommentClassifyService.selectById(id));
		return "jzweb/evaluationClassification/add";
	}


	@ResponseBody
	@GetMapping("/list")
	public Result<Page<JazUserCommentDO>> list(@RequestParam Integer current,@RequestParam Integer pageSize){
        return Result.ok(jazUserCommentService.getUserCommentList(null,null,current,pageSize));
	}


	@GetMapping("/add")
	@RequiresPermissions("jzweb:jazUserComment:add")
	String add(){
	    return "jzweb/jazUserComment/add";
	}

	@Log(value = "添加评价",sysModule = 8,operationType = 1)
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("jzweb:jazUserComment:add")
	public Result<String> save( JazUserCommentDO jazUserComment){
		//设置评价时间
		jazUserComment.setCommentTime(new DateTime());
		jazUserCommentService.insert(jazUserComment);
        return Result.ok();
	}


	@GetMapping("/edit/{id}")
	@RequiresPermissions("jzweb:jazUserComment:edit")
	String edit(@PathVariable("id") Long id,Model model){
		JazUserCommentDO jazUserComment = jazUserCommentService.selectById(id);
		model.addAttribute("jazUserComment", jazUserComment);
		return "jzweb/jazUserComment/edit";
	}
	
	@Log(value = "编辑并更新评价",sysModule = 8,operationType = 3)
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("jzweb:jazUserComment:edit")
	public Result<String>  update( JazUserCommentDO jazUserComment){
		boolean update = jazUserCommentService.updateById(jazUserComment);
		return update ? Result.ok() : Result.fail();
	}


	@GetMapping("/info/{id}")
	@RequiresPermissions("jzweb:jazUserComment:jazUserComment")
	String info(@PathVariable("id") Long id,Model model){
		JazUserCommentDO jazUserComment = jazUserCommentService.selectById(id);
		jazUserComment.setCommentTime(DateTime.of(jazUserComment.getCommentTime()));
		UserDO userDO = userService.selectById(jazUserComment.getCommentUserid());
		UserDO userDO1 = userService.selectById(jazUserComment.getCommentdObjectid());
		//获取评价对象姓名、评论人姓名
		jazUserComment.setName(userDO.getNickname());
		jazUserComment.setNames(userDO1.getNickname());
		model.addAttribute("jazUserComment", jazUserComment);
		return "jzweb/jazUserComment/info";
	}
	
	@Log(value = "删除评价",sysModule = 8,operationType = 2)
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("jzweb:jazUserComment:remove")
	public Result<String>  remove( Long id){
		jazUserCommentService.deleteById(id);
        return Result.ok();
	}
	
}
